﻿using System;
using Xunit;

namespace Gamemaster.Console
{
    public class RollCommandTests
    {
        [Fact]
        public void Simple()
        {
            RollCommand command = new RollCommand("d12");

            Assert.Equal(12, command.SidesOnDie);
            Assert.Equal(1, command.NumberOfDice);
            Assert.Equal(0, command.Modifier);
        }

        [Fact]
        public void WithModifier()
        {
            RollCommand command = new RollCommand("d12+5");

            Assert.Equal(12, command.SidesOnDie);
            Assert.Equal(1, command.NumberOfDice);
            Assert.Equal(5, command.Modifier);
        }

        [Fact]
        public void WithNumberOfDice()
        {
            RollCommand command = new RollCommand("2d12");

            Assert.Equal(12, command.SidesOnDie);
            Assert.Equal(2, command.NumberOfDice);
            Assert.Equal(0, command.Modifier);
        }

        [Fact]
        public void WithNumberOfDiceAndModifier()
        {
            RollCommand command = new RollCommand("2d12+5");

            Assert.Equal(12, command.SidesOnDie);
            Assert.Equal(2, command.NumberOfDice);
            Assert.Equal(5, command.Modifier);
        }

        [Fact]
        public void ShowDiceParameterGetsParsed()
        {
            RollCommand command = new RollCommand("showdice");

            Assert.True(command.ShowDice);
        }

        [Fact]
        public void ShowDiceDefaultsCorrectly()
        {
            RollCommand command = new RollCommand("roll");

            Assert.False(command.ShowDice);
        }

        [Fact]
        public void UnrecognizedParametersThrows()
        {
            Assert.Throws<ArgumentException>(() => new RollCommand("asdfsadf"));
        }
    }
}
